<template>
  <div>
    <nav-bar class="detail-nav">
      <div slot="left" class="back" @click="backHome">
        <img src="~assets/img/common/back.svg" alt="" />
      </div>
      <div slot="center" class="title">
        <div
          class="title-item"
          ref="titleitem"
          :key="index"
          v-for="(item, index) in titles"
          @click="titleClick(index)"
          :class="{ activeColor: currentIndex == index }"
        >
          {{ item }}
        </div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar";
export default {
  name: "Detailnavbar",
  components: { NavBar },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0,
    };
  },

  methods: {
    //   返回首页
    backHome() {
      this.$router.back();
      //   this.$router.go(-1);
    },
    //   点击标题高亮事件
    titleClick(index) {
      this.currentIndex = index;
      this.$emit('itemTab', index);
    },
  },
};
</script>

<style scoped>
.detail-nav {
  height: 40px;
}
.back img {
  vertical-align: middle;
  padding-left: 5px;
}

.title {
  display: flex;
  justify-content: center;
}
.title-item {
  flex: 1;
}
.activeColor {
  color: var(--color-tint);
}
</style>
